﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FlexminAPI;
using System.Diagnostics;

namespace TaskManager
{
	public class TaskSlave : ISlave
	{
		public ProcessInfo[] GetProcessesInfo()
		{
			List<ProcessInfo> procInfos = new List<ProcessInfo>();
			ProcessInfo info;
			foreach (Process proc in Process.GetProcesses())
			{
				info = new ProcessInfo(proc);
				if (!info.Allowed)
					continue;

				procInfos.Add(info);
			}

			return procInfos.ToArray();
		}

		public void Kill(int pid)
		{
			Process.GetProcessById(pid).Kill();
		}

		public void SetPriority(int pid, ProcessPriorityClass priority)
		{
			try
			{
				Process.GetProcessById(pid).PriorityClass = priority;
			}
			catch
			{
				// TODO: Error handling
			}
		}		
	}
}
